package day14;

import org.openjdk.jol.info.ClassLayout;

/**
 * @author du.senlin
 * @Title: 查看类内存分布详情
 * @Description:
 * @date 2020/8/10 20:19
 * @see <a href=""></a>
 */
public class JolTools {


    private String name;
    private String age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public static void main(String[] args) {
        // Object默认类数据为null，所以new一个Object占用16个字节
        JolTools o = new JolTools();
        o.setAge("1");
        o.hashCode();
        // 打印类分布详情
        System.out.println(ClassLayout.parseInstance(o).toPrintable());

        synchronized (o){
            System.out.println("同步代码块：");
            System.out.println(ClassLayout.parseInstance(o).toPrintable());
        }


    }

    /**
     *
     *  OFFSET  SIZE   TYPE DESCRIPTION                               VALUE
     *       0     4        (object header)                           09 00 00 00 (00001001 00000000 00000000 00000000) (9)
     *       4     4        (object header)                           00 00 00 00 (00000000 00000000 00000000 00000000) (0)
     *       8     4        (object header)                           e5 01 00 f8 (11100101 00000001 00000000 11111000) (-134217243)
     *      12     4        (loss due to the next object alignment)
     * Instance size: 16 bytes
     *
     *
     *  类{
     *      对象头  markword 锁的信息都存放在这里
     *      类引用  classpointer (默认开启压缩)
     *      类变量  instance data
     *      对齐   padding
     *  }
     *
     *
     *
     *
     *
     *
     *
     *
     * 锁升级步骤-------start-------
     * 无锁
     * 偏向锁
     * 轻量级锁
     * 重量级锁
     * 锁升级步骤-------end-------
     *
     *
     *
     */



}
